package com.lovo.controller;

import com.lovo.model.StudentDO;
import com.lovo.service.IStudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/stus")
public class StuController {
    @Resource
    private IStudentService stuService;
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(){
        return "hello index";
    }


    @GetMapping
    public List findAll(String name){
        System.out.println(name);
        return stuService.listAllStudent();
    }
    @GetMapping("/{id}")
    public StudentDO findById(@PathVariable("id") Long id){
        return stuService.findbyid(id);
    }
    @PostMapping
    public String save(@RequestBody StudentDO stuDTO){
        System.out.println(stuDTO);
        stuService.save(stuDTO);
        return "增加";
    }

    @PutMapping("/{id}")
    public String update(@PathVariable("id") Long id,@RequestBody StudentDO stuDTO){
        System.out.println("id:"+stuDTO);
        stuDTO.setId(id);
        stuService.update(stuDTO);
        return "update : "+stuDTO;
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Long id){
        stuService.del(id);
        return "delete "+id;
    }


}
